/**
 * Copyright 2015 - 2016 KeepSafe Software, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.getkeepsafe.relinker.elf;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 * Function description
 * class Dynamic32Structure
 */
public class Dynamic32Structure extends Elf.DynamicStructure {
    /**
     * Constructor
     *
     * @param parser ElfParser
     * @param header Elf.Header
     * @param baseOffset long
     * @param index int
     */
    public Dynamic32Structure(final ElfParser parser, final Elf.Header header, long baseOffset, final long index) {
        final ByteBuffer buffer = ByteBuffer.allocate(4);
        buffer.order(header.mIsBigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);

        long offset = baseOffset + (index * Constants.BUFFER_OFFSET_LONG_ID_CONSTANT);
        tag = parser.readWord(buffer, offset);
        val = parser.readWord(buffer, baseOffset + Constants.BUFFER_OFFSET_ID_CONSTANT);
    }
}
